import { getAction } from "@/command/netTool";
import { useDetail } from "@/hooks";

export const useRequest = () => {


    const [rootData] = useDetail(
        "/api/H5/util/getProductRoot", [],
        {
            callBack: (data: any[]) => {
                return data.map((e) => ({ text: e.name, value: e.id, children: [] }))
            }
        });
    const getLevelData = (item: any) => {
        getAction(`/api/H5/util/getProductLevel?id=${item.value}`).then((e) => {
            if (item.selectedOptions[item.tabIndex]['children']) {
                item.selectedOptions[item.tabIndex]['children'] = e.map((el: any) => ({ ...el, text: el.label })) as never
            }
        })
    }
    return {
        rootData,
        getLevelData,
    }
}